//
//  BindingOperation.swift
//  CSBind
//
//  Created by 万孟超 on 2023/12/23.
//

import Foundation

// MARK -- 双向绑定

/// 自定义一个双向绑定的中缀运算符
infix operator  <==>

public func <==><LT, RT, ValueType>(lhs: (LT?, ReferenceWritableKeyPath<LT, ValueType>), rhs: (RT?, ReferenceWritableKeyPath<RT, ValueType>)) -> CSBindDispose where ValueType: Any, LT: NSObject, RT: NSObject {
    return CSBidirectionalBindDispose(lhs.0, lhs.1, rhs.0, rhs.1)
}

public func <==><LT, RT, LV>(lhs: (LT?, ReferenceWritableKeyPath<LT, LV>), rhs: (RT?, String)) -> CSBindDispose where LV: Any, LT: NSObject, RT: NSObject {
    return CSBidirectionalBindDispose(lhs.0, lhs.1, rhs.0, rhs.1)
}

public func <==><LT, RT, RV>(lhs: (LT?, String), rhs: (RT?, ReferenceWritableKeyPath<RT, RV>)) -> CSBindDispose where RV: Any, LT: NSObject, RT: NSObject {
    return CSBidirectionalBindDispose(lhs.0, lhs.1, rhs.0, rhs.1)
}

public func <==><LT, RT>(lhs: (LT?, String), rhs: (RT?, String)) -> CSBindDispose where LT: NSObject, RT: NSObject {
    return CSBidirectionalBindDispose(lhs.0, lhs.1, rhs.0, rhs.1)
}

// MARK -- 单向绑定

/// 自定义一个单向绑定的中缀运算符
infix operator  ==>

public func ==><LT, RT, ValueType>(lhs: (LT?, ReferenceWritableKeyPath<LT, ValueType>), rhs: (RT?, ReferenceWritableKeyPath<RT, ValueType>)) -> CSBindDispose where ValueType: Any, LT: NSObject, RT: NSObject {
    return CSUnidirectionalBindDispose(lhs.0, lhs.1, rhs.0, rhs.1)
}

public func ==><LT, RT, ValueType>(lhs: (LT?, String), rhs: (RT?, ReferenceWritableKeyPath<RT, ValueType>)) -> CSBindDispose where ValueType: Any, LT: NSObject, RT: NSObject {
    return CSUnidirectionalBindDispose(lhs.0, lhs.1, rhs.0, rhs.1)
}

public func ==><LT, RT, ValueType>(lhs: (LT?, ReferenceWritableKeyPath<LT, ValueType>), rhs: (RT?, String)) -> CSBindDispose where ValueType: Any, LT: NSObject, RT: NSObject {
    return CSUnidirectionalBindDispose(lhs.0, lhs.1, rhs.0, rhs.1)
}

public func ==><LT, RT>(lhs: (LT?, String), rhs: (RT?, String)) -> CSBindDispose where LT: NSObject, RT: NSObject {
    return CSUnidirectionalBindDispose(lhs.0, lhs.1, rhs.0, rhs.1)
}
